package com.example.doma.contraller;

import com.example.doma.mapper.userMapper;
import com.example.doma.service.userService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.web.servlet.server.Session;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

@Controller
public  class indexcontraller {

    @RequestMapping({"/","/index.html"})
    public  String  index(){
        return "index";
    }


    @Autowired
    userService user;

    @RequestMapping("/user/login")
    public  String login(@RequestParam("username") String name, @RequestParam("password") String pass, Model model , HttpSession session, HttpServletRequest request)
    {

        if(user.istrue_password(name,pass))
        {
            request.setAttribute("logename",name);
            return "forward:/main.html";
        }

        else{
            model.addAttribute("msg","用户名或者密码错误");
            return "index";

    }

    }
}
